package com.example.bgmachine.bgmachine.produces;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.example.bgmachine.bgmachine.R;
import com.example.bgmachine.bgmachine.exts.SlovmeData;
import com.example.bgmachine.bgmachine.goods.HomepageGridRightMenuItemData;
import com.example.bgmachine.bgmachine.goods.HomepageLeftMenuItemData;
import com.example.bgmachine.bgmachine.goods.LeftSelectindex;
import com.example.bgmachine.bgmachine.homes.HomePages;
import com.example.bgmachine.bgmachine.orders.OrderContentData;
import com.example.bgmachine.bgmachine.specifs.SpecifData;

public class ScancodePopupView extends Dialog implements
        View.OnClickListener {
    Context context;


    private Boolean bool;
    private View.OnClickListener btnOnClick;
    public Button procduce_popup_cencel_btn = null;
    public Button spcwcif_popup_close_btn = null;

    public TextView produce_popup_view_progress_textview = null;
    public TextView produce_popup_view_name_textview = null;

    public HomepageLeftMenuItemData lefta = null;
    public HomepageGridRightMenuItemData righta = null;
    public SpecifData mSpecifData = null;
    public OrderContentData orderContentData= null;
    public int mTypeindex=-1; //1为普通  2 为订单
    /**
     * @param @param btnOnClick
     * @return void
     * @throws
     * @Description: 可以自定义button事件
     * @author Sunday
     */
    public void setBtnOnClick(View.OnClickListener btnOnClick) {
        this.btnOnClick = btnOnClick;

    }

    public void setBtnOkClick(String text,
                              View.OnClickListener btnOnClick) {
        this.btnOnClick = btnOnClick;

    }

    public ScancodePopupView(Context context) {
        super(context, R.style.SundayDialogs);
        this.context = context;
        bool = true;


        Log.d("aaa", "aaa===2");
        //create();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.produce_view_scan_code_dialog);
        hideBottomUIMenu();
        // 设置窗口属性
        if (getWindow() != null) {
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            getWindow().setDimAmount(0f);
            getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            );
            getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
            );
        }

        init();
        //  setCancel(bool, "");

        Log.d("aaa", "aaa===1");
    }
    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(params);


        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        Window myWindow = this.getWindow();
        myWindow.setFlags(flag, flag);

        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);


        }

        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
            }
        });
    }
    void init() {
        procduce_popup_cencel_btn = findViewById(R.id.procduce_popup_cencel_btn);
        procduce_popup_cencel_btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                dismiss();
                if( mTypeindex == 1 ){
                    if(  lefta != null && righta != null && mSpecifData != null){
                        SlovmeData.getSlovmeData().setLefta(lefta);
                        SlovmeData.getSlovmeData().setRighta(righta);
                        HomePages.mHomePages.setProduceProgress(mSpecifData,righta.getMenuNames()+"-"+mSpecifData.getTypename(),mSpecifData.getTypeOrder() ,mSpecifData.getContent());

                        //HomePages.mHomePages.setSpecifPopuView(lefta,righta,righta.getMenuNames(),righta.getContents());
                    }
                }
                if( mTypeindex == 2 ){
                  //  orderContentData
                    HomePages.mHomePages.makeOrderDetail( orderContentData );
                }

            }
        });
        spcwcif_popup_close_btn= findViewById(R.id.spcwcif_popup_close_btn);
        spcwcif_popup_close_btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                 dismiss();
            }
        });

        produce_popup_view_progress_textview = findViewById(R.id.produce_popup_view_progress_textview);

        produce_popup_view_name_textview = findViewById(R.id.produce_popup_view_name_textview);

    }
    public  void  setLeft( HomepageLeftMenuItemData lefts){
         lefta = lefts;
    }
    public void setRight( HomepageGridRightMenuItemData rights ){
         righta = rights;
    }
    public void setSpecifData( SpecifData specifData ){
        mSpecifData = specifData;
    }
    public void setOrderContentData( OrderContentData items ){
        orderContentData = items;
    }

    public void  setTypes(int indexs){
        mTypeindex = indexs;
    }
    public void closeView() {

        dismiss();
    }

    public void setNameInfor(String infors) {
        if (produce_popup_view_name_textview != null) {
            produce_popup_view_name_textview.setText(infors);
        }
    }

    public void setRunTime(String infors) {

        setRunInfor(infors);

    }

    public void setRunInfor(String infors) {
        if (produce_popup_view_progress_textview != null) {
            produce_popup_view_progress_textview.setText(infors);
        }
    }

    /*
     *
     */
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        if (isShowing()) {
            //   dismiss();
        }
    }
}
